package com.fstec.ks.master.netty;

import com.sinotn.gson.GsonFacade;
import com.sinotn.ks.definition.Message;
import com.sinotn.ks.definition.MessageFile;

/**
 * 考试消息异常
 * @Title ExamMessageException.java
 * @Package com.sinotn.ks.definition.provider.exception
 * @Description
 * Copyright: Copyright (c) 2015
 * Company:北京信诺软通
 *
 * @author <a href="mailto:xieqj@sinotn.com">谢启进</a>
 * @date 2016年11月13日 下午12:41:54
 * @version V1.0
 */
public class ExamExceptionMessage extends RuntimeException implements Message{
	private static final long serialVersionUID = 1L;
	private int type;
	private long token;
	private String method;
	private boolean disconnect=false;

	public ExamExceptionMessage(int type, String msg){
		super(msg);
		this.type=type;
	}


	public ExamExceptionMessage(int type, String msg, Throwable e){
		super(msg, e);
		this.type=type;
	}

	public void setToken(long token) {
		this.token = token;
	}


	public void setMethod(String method) {
		this.method = method;
	}

	public String getMethod() {
		return method;
	}

	@Override
	public int getType() {
		return this.type;
	}

	@Override
	public long getToken() {
		return this.token;
	}

	public boolean isDisconnect() {
		return disconnect;
	}


	public void setDisconnect(boolean disconnect) {
		this.disconnect = disconnect;
	}


	@Override
	public String getText() {
		if(this.method==null){
			return this.getMessage();
		}else{
			StringBuilder sb=new StringBuilder();
			sb.append("{");
			sb.append("\"method\":\"").append(this.method).append("\"");
			if(this.getMessage()!=null){
				sb.append(",\"text\":\"").append(GsonFacade.escapeText(this.getMessage(), false)).append("\"");
			}
			sb.append("}");
			return sb.toString();
		}
	}

	@Override
	public MessageFile[] getFiles() {
		return null;
	}
}
